#include "math.h"
#include "SDL/SDL.h"
#include "SDLGraphics.h"
#include "global.h"
#include "gamemath.h"
#include "collisionHandle.h"
#include <stdio.h>
#include <iostream>
using namespace std;

extern collisionHandle* g_col;

class tower
{

public:
int x,y,health,level;
int collisionid;
float angle;
bool m_active;
void kill()
{
	m_active=false;
	angle=0;
	g_col->removeBox(collisionid);
}
void Process()
{
	//angle = gamemath::anglefromline(x,y,you.x,you.y);
	angle++;
	if(angle>=360)
	{
		//shiftColId(id);
		kill();
	}
}

void Init(int x_, int y_)
{
	
	x = floor((float)x_/32)*32;
	y = floor((float)y_/32)*32;
	collisionid = g_col->addBox(x,y,64,64);
	m_active = true;
}
};

class TowerPool
{
public:

	polarcoord guntop, gunmiddle, towermiddle;
    static const int POOL_SIZE = 10;
    tower towers_[POOL_SIZE];
	void shiftColId(int id)
	{
	for (int i = 0; i < POOL_SIZE; i++)
        {
		    if(towers_[i].m_active)
            {
				if(towers_[i].collisionid>id)
				{
					towers_[i].collisionid--;
				}
            }
	}
	}
    void Process()
    {
        for (int i = 0; i < POOL_SIZE; i++)
        {
            if(towers_[i].m_active)
            {
                towers_[i].Process();
            }
        }
    }
    void Create(int x, int y)
    {
        // find an available bullet
        for (int i = 0; i < POOL_SIZE; i++)
        {
            if (!towers_[i].m_active)
            {
                towers_[i].Init(x, y);
                return;
            }
        }
    }
};